$(function () {

    // 初始化操作类型下拉框
    var option = "";
    for (var key in operType) {
        option += '<option value="' + key + '">' + operType[key] + '</option>'
    }
    $('[name="operateType"]').append(option).select2({
        placeholder: "请选择",
        allowClear: true,
        language: "zh-CN"
    });

    operateTable();
});

function operateTable() {
    $('#operateTable').dataTableExtend({
        "ajax": sysInfo.basePath + "/sys_record/credential_sys_record_data.do",
        "fnServerParams": function (aoData) {
            aoData.operateType = $("[name='operateType'] option:selected").val();
            aoData.certificateCode = $("[name='certificateCode']").val();
            return aoData;
        },
        "aoColumns": [
            {
                "title": "序号",
                "render": function (data, type, full, meta) {
                    return meta.row + 1;
                },
                "orderable": false
            },
            {
                "title": "业务编号",
                "data": "workNo",
                "orderable": false
            },
            {
                "title": "操作类型",
                "data": "operateType",
                "orderable": false,
                "render": function (data, type, full, meta) {
                    var str = "";
                    for (var key in operType) {
                        if (key == data) {
                            str = operType[key];
                            break;
                        }
                    }
                    return str;
                }
            },
            {
                "title": "操作时间",
                "data": "operateTime",
                "orderable": false
            },
            {
                "title": "操作人",
                "data": "operaterName",
                "orderable": false
            },
            {
                "title": "备注",
                "data": "remarks",
                "orderable": false
            }
        ],
    });

}

/**
 * 加载收支数据
 */
function loadAccountsData(obj) {
    var id = $('[name=id]').val();
    var accountsType = $('[name=accountsType]').val();
    $.post(sysInfo.basePath + "/zs/general_credential/accounts_detail.do", {id: id, accountsType: accountsType}, function (result) {
        if (result.code == 0) {
            var datas = result.data.data;
            $(obj).empty();
            $(obj).append("<thead>\n" +
                "<tr>\n" +
                "    <th>所属订单</th>\n" +
                "    <th>收支类型</th>\n" +
                "    <th>时间</th>\n" +
                "    <th>金额（元）</th>\n" +
                "    <th>备注</th>\n" +
                "</tr>\n" +
                "</thead><tbody>");
            if (!checkIsEmpty(datas) && datas.length > 0) {
                $.each(result.data.data, function (i, item) {
                    $(obj).append("<tr>\n" +
                        "<td>" + item.orderBusinessNo + "</td>\n" +
                        "<td>" + item.type + "</td>\n" +
                        "<td>" + item.performanceTime + "</td>\n" +
                        "<td>" + fmtMoney(item.amount) + "</td>\n" +
                        "<td>" + item.remark + "</td>\n" +
                        "</tr>");
                });
                $(obj).append("</tbody>");
                $("[name='payCount']").html(fmtMoney(result.data.zAmount));
                $("[name='receiptCount']").html(fmtMoney(result.data.sAmount));
            } else {
                $(obj).append("<tr>\n" +
                    "<td colspan='5'><center>没有数据</center></td>\n" +
                    "</tr></tbody>");
            }

        } else {
            DGG.Errors(result.msg);
            return false;
        }
    });
}